package org.nado.member;

import javax.inject.Inject;

import org.apache.log4j.Logger;
import org.nado.web.HomeController;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.SessionAttributes;

@Service
@Transactional(propagation=Propagation.SUPPORTS)
public class MemberServiceImpl implements MemberService {

	private static final Logger logger = Logger.getLogger("MemberServiceImpl");
	
	@Inject
	MemberDAO dao;
	
	@Override
	@Transactional(propagation=Propagation.REQUIRED , readOnly=false)
	public void regist(MemberVO vo) throws Exception {
		
		logger.info("regist............." + vo);
		dao.create(vo);
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED , readOnly=true)
	public MemberVO get(String mem_id) throws Exception {
		
		logger.info("get............." + mem_id);
		return dao.read(mem_id);
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED , readOnly=false)
	public void modify(MemberVO vo) throws Exception {
		
		logger.info("modify............." + vo);
		dao.update(vo);
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED , readOnly=false)
	public void remove(String mem_id) throws Exception {

		logger.info("remove............." + mem_id);
		dao.delete(mem_id);
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED , readOnly=true)
	public MemberVO login(String mem_id, String mem_pw) throws Exception {
		
		MemberVO vo = get(mem_id);
		
		logger.info("service.login......."+vo);
		
		if(vo == null){
			return null;
		}else if(!mem_pw.equals(vo.getMem_pw())){
			return null;
		}else{
			return vo;
		}
	}


}
